﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.z00_zzglMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void z00_zzgl_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            z00_zzglMgr mgr = new z00_zzglMgr();
            e.Total = int.Parse(mgr.GetRecordCount_z00_zzgl(e.Parameters[z00_zzgl_Filter.ParamPrefix]));
            IList<z00_zzgl> list = mgr.FindAllByPage_z00_zzgl(e.Start.ToString(), e.Limit.ToString(), e.Parameters[z00_zzgl_Filter.ParamPrefix]);
            z00_zzgl_MainStore.DataSource = list;
            z00_zzgl_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            z00_zzglMgr mgr = new z00_zzglMgr();
            RowSelectionModel sm = z00_zzgl_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                z00_zzgl _z00_zzgl = new z00_zzgl();
                _z00_zzgl.jsdh = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_z00_zzgl(_z00_zzgl))
                {
                    log.Debug("z00_zzgl中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            z00_zzgl_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            z00_zzglMgr mgr = new z00_zzglMgr();
            z00_zzgl _z00_zzgl = new z00_zzgl();
            if (Hid.Text.Length > 0)
                _z00_zzgl = mgr.FindById_z00_zzgl(int.Parse(Hid.Text));
            
			_z00_zzgl.dqbm = Txtdqbm.Text.Trim();
			_z00_zzgl.dzbm = Txtdzbm.Text.Trim();
			_z00_zzgl.zbh = Txtzbh.Text.Trim();
			_z00_zzgl.cbh = Txtcbh.Text.Trim();
			_z00_zzgl.zyid = Txtzyid.Text.Trim();
			_z00_zzgl.grbm = Txtgrbm.Text.Trim();
			_z00_zzgl.hzxm = Txthzxm.Text.Trim();
			_z00_zzgl.rbh = Txtrbh.Text.Trim();
			_z00_zzgl.brxm = Txtbrxm.Text.Trim();
			_z00_zzgl.xb = Txtxb.Text.Trim();
			_z00_zzgl.brnl = Txtbrnl.Text.Trim();
			_z00_zzgl.hzgx = Txthzgx.Text.Trim();
			_z00_zzgl.lxdh = Txtlxdh.Text.Trim();
			_z00_zzgl.sfzh = Txtsfzh.Text.Trim();
			_z00_zzgl.hkdz = Txthkdz.Text.Trim();
			_z00_zzgl.hbh = Txthbh.Text.Trim();
			_z00_zzgl.ylzh = Txtylzh.Text.Trim();
			_z00_zzgl.zybh = Txtzybh.Text.Trim();
			_z00_zzgl.jjlx = Txtjjlx.Text.Trim();
			_z00_zzgl.rysj = Txtrysj.Text.Trim();
			_z00_zzgl.cysj = Txtcysj.Text.Trim();
			_z00_zzgl.zycs = int.Parse(TxtNumzycs.Text.Trim());
			_z00_zzgl.zyts = int.Parse(TxtNumzyts.Text.Trim());
			_z00_zzgl.jgdm = Txtjgdm.Text.Trim();
			_z00_zzgl.jgjb = Txtjgjb.Text.Trim();
			_z00_zzgl.ryzd = Txtryzd.Text.Trim();
			_z00_zzgl.zdmc = Txtzdmc.Text.Trim();
			_z00_zzgl.fyhj = Txtfyhj.Text.Trim();
			_z00_zzgl.mxhj = Txtmxhj.Text.Trim();
			_z00_zzgl.kbhj = Txtkbhj.Text.Trim();
			_z00_zzgl.shkbje = Txtshkbje.Text.Trim();
			_z00_zzgl.zfhj = Txtzfhj.Text.Trim();
			_z00_zzgl.sjhj = Txtsjhj.Text.Trim();
			_z00_zzgl.cehj = Txtcehj.Text.Trim();
			_z00_zzgl.bsbl = Txtbsbl.Text.Trim();
			_z00_zzgl.sfje = Txtsfje.Text.Trim();
			_z00_zzgl.fdje = Txtfdje.Text.Trim();
			_z00_zzgl.czry = Txtczry.Text.Trim();
			_z00_zzgl.hsry = Txthsry.Text.Trim();
			_z00_zzgl.shry = Txtshry.Text.Trim();
			_z00_zzgl.fkry = Txtfkry.Text.Trim();
			_z00_zzgl.cnry = Txtcnry.Text.Trim();
			_z00_zzgl.zljg = Txtzljg.Text.Trim();
			_z00_zzgl.hsjg = Txthsjg.Text.Trim();
			_z00_zzgl.shjg = Txtshjg.Text.Trim();
			_z00_zzgl.hkjg = Txthkjg.Text.Trim();
			_z00_zzgl.clrq = Txtclrq.Text.Trim();
			_z00_zzgl.hsrq = Txthsrq.Text.Trim();
			_z00_zzgl.shrq = Txtshrq.Text.Trim();
			_z00_zzgl.bcrq = Txtbcrq.Text.Trim();
			_z00_zzgl.ecje = Txtecje.Text.Trim();
			_z00_zzgl.shdfbz = Txtshdfbz.Text.Trim();
			_z00_zzgl.bz = Txtbz.Text.Trim();
			_z00_zzgl.hkbz = Txthkbz.Text.Trim();
			_z00_zzgl.bzxx = Txtbzxx.Text.Trim();
			_z00_zzgl.szbz = Txtszbz.Text.Trim();
			_z00_zzgl.fpid = Txtfpid.Text.Trim();
			_z00_zzgl.dybz = Txtdybz.Text.Trim();
			_z00_zzgl.hsx = Txthsx.Text.Trim();
			_z00_zzgl.chsx = Txtchsx.Text.Trim();
			_z00_zzgl.fphm = Txtfphm.Text.Trim();
			_z00_zzgl.zyfyhj = Txtzyfyhj.Text.Trim();
			_z00_zzgl.ljzyfy = Txtljzyfy.Text.Trim();
			_z00_zzgl.ljzykb = Txtljzykb.Text.Trim();
			_z00_zzgl.ljzybc = Txtljzybc.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_z00_zzgl(_z00_zzgl);
            else
                isok = mgr.Add_z00_zzgl(_z00_zzgl);
            if (isok)
            {
                z00_zzgl_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("z00_zzgl中执行了保存（插入或修改），并成功");
                z00_zzgl_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}